package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.ov.ResultDataTable;
import com.power.service.TowerService;
import com.power.service.impl.TowerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/04 9:02
 * Description:从数据库查询所有的杆塔信息数据，返回给前端页面
 * Version: V1.0
 */
@WebServlet("/queryListPower.do")
public class QueryTowerList extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));

        TowerService towerService = new TowerServiceImpl();
        response.setContentType("application/json;charset=utf-8");
        ResultDataTable resultData = null;
        try {
            resultData = towerService.queryListPower(page,limit);
            response.getWriter().write(JSON.toJSONString(resultData));
            response.getWriter().flush();
            response.getWriter().close();
        } catch (SQLException e) {
            e.printStackTrace();
        }



    }
}
